//
//  HY_LRefreshView.swift
//  Refresh
//
//  Created by rimi on 16/10/9.
//  Copyright © 2016年 赖虹宇. All rights reserved.
//

import UIKit

class HY_LRefreshView: UIView {
   
    //定义一个枚举属性，来区别做什么事情
    //didSet 不能索引  可以看做oc 的 setter方法
    var refreshState : hy_LRefreshState = .nomol {
        didSet {
            switch refreshState {
            case .nomol:
                //先恢复视图的状态
                arrowView.isHidden = false
                activityView.stopAnimating()
                
                titleL.text = "恩，再用点力"
                UIView.animate(withDuration: 0.25, animations: { 
                    self.arrowView.transform = CGAffineTransform.identity
                })
            case .pulling :
                titleL.text = "放手就刷新"
                //通过苹果系统隐式的就近原则，通过减去0.001 他会按逆时针旋转
                UIView.animate(withDuration: 0.25, animations: { 
                    self.arrowView.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI) - 0.001)
                })
            case .willRefresh:
                titleL.text = "正在刷新"
                arrowView.isHidden = true
                activityView.startAnimating()
            }
        }
    }
   
    @IBOutlet weak var arrowView: UIImageView!
    @IBOutlet weak var activityView: UIActivityIndicatorView!
    @IBOutlet weak var titleL: UILabel!
 
    class func refreshV() -> HY_LRefreshView {
        //获取xib
        let xib = UINib(nibName: "HY_LRefreshView", bundle: nil)
        
        return xib.instantiate(withOwner: nil, options: [:])[0]  as! HY_LRefreshView
    }
}
